package cn.opopopo.design_pattern_learn.行为型.中介者.demo2;


import cn.opopopo.design_pattern_learn.行为型.中介者.demo1.ChatRoom;
import cn.opopopo.design_pattern_learn.行为型.中介者.demo1.User;

// 测试类
public class MediatorDemo {
    public static void main(String[] args) {
//        System.out.println("=== 聊天室示例 ===");
//        testChatRoom();
        
        System.out.println("\n=== 房屋中介示例 ===");
        testHouseMediator();
    }
    
    public static void testChatRoom() {
        // 创建聊天室中介者
        ChatRoom chatRoom = new ChatRoom();
        
        // 创建用户
        User user1 = new User(chatRoom, "张三");
        User user2 = new User(chatRoom, "李四");
        User user3 = new User(chatRoom, "王五");
        
        // 将用户添加到聊天室
        chatRoom.addUser(user1);
        chatRoom.addUser(user2);
        chatRoom.addUser(user3);
        
        // 用户发送消息
        user1.sendMessage("大家好！");
        System.out.println();
        user2.sendMessage("你好，张三！");
        System.out.println();
        user3.sendMessage("欢迎加入聊天室！");
    }
    
    public static void testHouseMediator() {
        // 创建房屋中介系统
        HouseMediator houseMediator = new HouseMediator();
        
        // 创建房主
        HouseOwner owner1 = new HouseOwner(houseMediator, "房东A");
        HouseOwner owner2 = new HouseOwner(houseMediator, "房东B");
        
        // 添加房源
        owner1.addHouse(new House("北京市朝阳区", 5000));
        owner1.addHouse(new House("北京市海淀区", 4500));
        owner2.addHouse(new House("北京市西城区", 6000));
        
        // 创建租客
        Tenant tenant1 = new Tenant(houseMediator, "租客小明", 5000);
        Tenant tenant2 = new Tenant(houseMediator, "租客小红", 4000);
        
        // 将房主和租客注册到中介系统
        houseMediator.addHouseOwner(owner1);
        houseMediator.addHouseOwner(owner2);
        houseMediator.addTenant(tenant1);
        houseMediator.addTenant(tenant2);
        
        // 房主发布房源信息
        owner1.sendMessage("有两套房子出租");
        System.out.println();
        
        // 租客发布需求
//        tenant1.sendMessage("寻找月租5000以下的房子");
    }
}